﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TruongVu.Business;

namespace TruongVuWebsite.Admin
{
    public partial class ServiceAccouting : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                return;
            }

            int id = 1;
            if (Request["id"] != null)
            {
                int.TryParse(Request["id"], out id);
            }

            ServiceModel serviceModel = new ServiceModel();
            TruongVu.Data.Service service = null;
            switch (id)
            {
                case 2:
                    service = serviceModel.GetServiceIncorpotation();
                    lbTitle.Text = "Thành lập công ty";
                    break;
                case 3:
                    service = serviceModel.GetServiceTaxReport();
                    lbTitle.Text = "Xin Visa";
                    break;
                case 4:
                    service = serviceModel.GetServiceVisa();
                    lbTitle.Text = "Thành lập công ty";
                    break;
                case 5:
                    service = serviceModel.GetServiceWorkPermi();
                    lbTitle.Text = "Giấy phép lao động";
                    break;
                case 6:
                    service = serviceModel.GetServiceWorkPermi();
                    lbTitle.Text = "Vé máy bay";
                    break;
                default:
                    service = serviceModel.GetServiceAccounting();
                    lbTitle.Text = "Kế toán - kiểm toán";
                    break;
            }

            if (service != null)
            {
                txtFull.Value = service.Details;
            }
        }

        protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                int id = 1;
                switch (Request["id"])
                {
                    case "2":
                        id = 2;
                        break;
                    case "3":
                        id = 3;
                        break;
                    case "4":
                        id = 4;
                        break;
                    case "5":
                        id = 4;
                        break;
                    default:
                        id = 1;
                        break;
                }

                ServiceModel serviceModel = new ServiceModel();
                serviceModel.ModifyService(id, this.txtFull.Value);

                this.DisplayMessage(this, "Lưu thành công.");
            }
            catch
            {
                this.DisplayMessage(this, "Lưu thất bại.");
            }
        }

        private void DisplayMessage(Control page, string msg)
        {
            string myScript = String.Format("alert('{0}');", msg);

            ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);
        }
    }
}